package com.jdk8;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class LocalDateTimeDemo {


    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        System.out.println(now.getMonth().getValue());
        System.out.println("减一月"+now.minusMonths(1));
        System.out.println("加一月"+now.plusMonths(1));
        System.out.println("修改月份"+now.withMonth(8));

        System.out.println("---------------");
        LocalDateTime of = LocalDateTime.of(2008,8,8,8,8,8);
        System.out.println(of);

        System.out.println("--------------");
        //  DateTimeFormatter
        LocalDateTime timeDate=LocalDateTime.now();
        System.out.println("格式化之前"+timeDate);

        // 格式化
        DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        String result=formatter.format(timeDate);
        System.out.println("格式化之后"+result);

        // 解析
        String time="2014年11月26日";
        LocalDate parse = LocalDate.parse(time, formatter);
        System.out.println(parse);
        System.out.println("-----------------------");
        System.out.println("------------------");
        // 时区
        Instant nowTime=Instant.now();
        System.out.println("当前的时间"+nowTime);

        ZonedDateTime zonedDateTime=Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println(zonedDateTime);
    }
}
